﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Web.Script.Serialization;

namespace WebApplication2
{
    public partial class About : Page
    {

        public class GameState
        {
            public List<ChessMan> AllChessMen;
            public string WhoStrokeFirst;
            public string WhoPlayWhite;
            //public GameState();
        }
        //
        // GET: /TestManyParam/
        public class ChessMan
        {

            public string Name;
            public int X;
            public int Y;

            //public ChessMan();
        }
        
        protected void Page_Load(object sender, EventArgs e)
        {
            string host = "http://localhost:56432", id = "qwe", name = "ghbdtn", lname = "dfg";
            string uri;


          // string uri = String.Format("{0}/Hello/HiThere?id=wer&&name={2}&&lname={3}", host, id, name,lname);
           // uri = "http://localhost:56432//Hello/";
            uri = "http://localhost:56432//Hello/Res?2";

           ////Create Request
            HttpWebRequest myHttpWebRequest = (HttpWebRequest)HttpWebRequest.Create(uri);
            myHttpWebRequest.Method = "GET";
            myHttpWebRequest.ContentType = "text/xml; encoding='utf-8'";

           ////Get Response
           HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();

            //запрос 
            WebClient wc = new WebClient();
            wc.DownloadDataCompleted += wc_DownloadDataCompleted;
            wc.DownloadDataAsync(new Uri(uri));

        }

        void wc_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
        {
            //рабочий код

            
            Stream str = new MemoryStream(e.Result);
            DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(GameState));
            GameState response = js.ReadObject(str) as GameState;
            
            
        }
        /// <summary>
        /// Десериализация
        /// </summary>

        /*
         * 
        Stream str = new MemoryStream(Encoding.Unicode.GetBytes(e.Result));
        DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(string));
        string response = js.ReadObject(str) as string;
         * 
        */
        
    }
}